package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Map;

import com.ruoyi.system.domain.IdDto;
import com.ruoyi.system.domain.PushMsgDto;
import jakarta.servlet.http.HttpServletResponse;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysPushRecord;
import com.ruoyi.system.service.ISysPushRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息推送Controller
 *
 * @author ruoyi
 * @date 2025-08-31
 */
@RestController
@RequestMapping("/system/record")
public class SysPushRecordController extends BaseController
{
    @Autowired
    private ISysPushRecordService sysPushRecordService;

    /**
     * 查询消息推送列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPushRecord sysPushRecord)
    {
        List<Map<String, Object>> list = sysPushRecordService.selectSysPushRecords(sysPushRecord);
        startPage();
        return getDataTable(list);
    }

    /**
     * 导出消息推送列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "消息推送", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPushRecord sysPushRecord)
    {
        List<SysPushRecord> list = sysPushRecordService.selectSysPushRecordList(sysPushRecord);
        ExcelUtil<SysPushRecord> util = new ExcelUtil<SysPushRecord>(SysPushRecord.class);
        util.exportExcel(response, list, "消息推送数据");
    }

    /**
     * 获取消息推送详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysPushRecordService.selectSysPushRecordById(id));
    }

    /**
     * 新增消息推送
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "消息推送", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPushRecord sysPushRecord)
    {
        return toAjax(sysPushRecordService.insertSysPushRecord(sysPushRecord));
    }

    /**
     * 修改消息推送
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "消息推送", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPushRecord sysPushRecord)
    {
        return toAjax(sysPushRecordService.updateSysPushRecord(sysPushRecord));
    }

    /**
     * 修改消息推送
     */
    @Log(title = "消息推送", businessType = BusinessType.UPDATE)
    @PutMapping("/editV2")
    public AjaxResult editV2(@RequestBody SysPushRecord sysPushRecord)
    {
        return toAjax(sysPushRecordService.updateSysPushRecord(sysPushRecord));
    }

    /**
     * 删除消息推送
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "消息推送", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return sysPushRecordService.deleteSysPushRecordByIds(ids);
    }

    @PostMapping("/push_message")
    public AjaxResult pushMessage(@RequestBody PushMsgDto dto){
        return sysPushRecordService.pushMessage(dto);
    }

    @PostMapping("/notice_list")
    public AjaxResult noticeList(){
        return sysPushRecordService.noticeList();
    }

    @PreAuthorize("@ss.hasPermi('system:record:detail')")
    @PostMapping("/notice_detail")
    public AjaxResult noticeDetail(@RequestBody IdDto dto){
        return sysPushRecordService.noticeDetail(dto);
    }

    @GetMapping("/notice_app_list")
    public TableDataInfo noticeAppList(SysPushRecord sysPushRecord){
        startPage();
        List<SysPushRecord> list = sysPushRecordService.noticeAppList(sysPushRecord);
        return getDataTable(list);
    }

    @PostMapping("/test")
    public AjaxResult test(@RequestBody PushMsgDto dto){
        return sysPushRecordService.test(dto);
    }


    @GetMapping("/view")
    public AjaxResult view(@RequestParam(value = "batchNo",required = false) String batchNo){
        return sysPushRecordService.view(batchNo);
    }
}
